﻿/*
* 时间：2019年7月 
* 作者：潘意
*/
using HC.View;
using HC.View.Properties;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Resources;
using System.Text;
using System.Windows.Forms;
using EMRView;
using EMRView.Extensions.HCAttribute;

namespace EMRView.Extensions.Command.StandardCommand.Edit
{
    [Command(CommandType.编辑, "Font", "字体")]
    public class FontCommand : BaseCommand
    {
        public override Icon CommandIcon
        {
            get
            {
                return Properties.HCResource.默认;
            }
        }

        public override object Execute(HCEmrView view, bool showDefaultUI = false, params object[] para)
        {
            if (para != null && para[0] is string)
            {
                view.ApplyTextFontName(para[0] as string);
                if (!view.Focused)
                    view.Focus();
            }
            return null;
        }

        public override void InitControl(object control)
        {
            if (control is ToolStripComboBox)
            {
                var fontComboBox = control as ToolStripComboBox;
                System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
                fontComboBox.Items.Clear();
                foreach (System.Drawing.FontFamily family in fonts.Families)
                {
                    fontComboBox.Items.Add(family.Name);
                }
                fontComboBox.SelectedIndex = fontComboBox.Items.IndexOf("宋体");
            }
        }
    }
}
